from dp_analysis.db.connection import Mysql


def search_region(db):
    region_set = set()
    with Mysql("dp", db) as mysql:
        connection = mysql.engine.connect()
        for (reg, ) in connection.execute("SELECT region FROM regional_table_of_delicacies;").fetchall():
            region_set.add(reg)
    return region_set


def search_cuisine(db, region):
    cuisine_set = set()
    with Mysql("dp", db) as mysql:
        connection = mysql.engine.connect()
        for (cui, ) in connection.execute("SELECT "
                                          "DISTINCT category "
                                          "from shop_info "
                                          "WHERE category NOT IN ('评论', '热门', '口味', '环境', '服务') "
                                          "AND region={!r};".format(region)).fetchall():
                cuisine_set.add(cui)
    return cuisine_set
